#!/bin/bash
###content
#FROM ubuntu
#
#ENV PORT=2222
#
#RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && \
#sed -i "s@http://ports.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && \
#apt update 
#
#RUN echo "root:root" | chpasswd && apt install -y openssh-server vim net-tools && \
#sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config && \
#sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/'  /etc/ssh/sshd_config && \
#sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config && \
#sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
#sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config
#
#ENTRYPOINT sed -i "s/#Port 22/Port ${PORT}/" /etc/ssh/sshd_config && service ssh start && bash
###content

target=$1
if [ "$target" = "" ] ;then
    target=sshd-docker
fi

if [ "${target#*.}" != "dockerfile" ] ;then
    target=${target}.dockerfile
fi

if [ "$(basename ${target})" = "${target}" ] ;then
    target=$(pwd)/${target}
else
    if [ ! -d $(dirname ${target}) ] ;then
        target=$(pwd)/$(basename ${target})
    fi
fi

sed -n '/^###content/,/^###content/s/^#//p' $0 | sed '1d;$d' > ${target}
if [ -f $target ] ;then
    echo "Successfully done:$target"
fi
